package org.scirp.ijmis.client.interceptor;

import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
import org.scirp.ijmis.action.base.BaseAction;

public class WsClinetAuthHandler extends BaseAction implements CallbackHandler {

	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
		for (int i = 0; i < callbacks.length; i++) {
			WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
			int usage = pc.getUsage();
			if (usage == WSPasswordCallback.USERNAME_TOKEN) {
				pc.setIdentifier(getText("userName"));
				pc.setPassword(getText("password"));
			} else if (usage == WSPasswordCallback.SIGNATURE) {
				pc.setPassword("keyPassword");
			}
		}
	}
}
